TASK_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

include ../config.mk

# Input(s)
SRC := $(TASK_DIR)/src/run_models.R
PROD_ROSTER_W_COSTS := $(BENEFIT_COST_PIPELINE)/calculate_cost_of_violence/output/prod_roster_w_costs.feather
COVAR_CONFIG := $(TASK_DIR)/../run_regressions/hand/covariate_sets.yaml

# Output(s)
OUT_FILE := $(OUT_DIR)/reg_results.feather

## regression_table  : Perform and write out regression results
.PHONY : regression_table
regression_table : $(OUT_FILE)

$(OUT_FILE) : $(SRC) $(TASK_FNS) $(TASK_CONFIG) $(PROJECT_CONFIG) $(COVAR_CONFIG) $(PROD_ROSTER_W_COSTS)
		@mkdir -p $(OUT_DIR)
		$(R_script) --vanilla $(SRC) \
		--TASK_FNS=$(TASK_FNS) \
		--TASK_CONFIG=$(TASK_CONFIG) \
		--PROJECT_CONFIG=$(PROJECT_CONFIG) \
		--COVAR_CONFIG=$(COVAR_CONFIG) \
		--PROD_ROSTER_W_COSTS=$(PROD_ROSTER_W_COSTS) \
		--OUT_FILE=$(OUT_FILE)

## clean             : Remove auto-generated files.
.PHONY : clean
clean :
	rm -r $(out_file)

## variables         : List variables
.PHONY : variables
variables :
	@echo PROJECT_DIR: $(PROJECT_DIR)
	@echo TASK_DIR: $(TASK_DIR)
	@echo SRC: $(SRC)
	@echo IN_FILES: $(PROD_ROSTER_W_COSTS)
	@echo out_file: $(OUT_FILE)

.PHONY : help
help : makefile
	@sed -n 's/^##//p' $<
